package admin.controllers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.DealModel;
import models.StoreItemModel;
import models.TransactionModel;
import admin.data.DealData;
import admin.data.ProductData;
import admin.data.StoreItemData;
import admin.data.TransactionData;


public class ListTransactionServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException {
		response.setCharacterEncoding("UTF-8");
		
		String path = ((HttpServletRequest) request).getRequestURI();
		String storeItemId = path.replaceAll("/admin/transaction/list/", "");
		
		StoreItemData storeItemData = new StoreItemData();
		StoreItemModel storeItemModel = new StoreItemModel();
		storeItemModel = storeItemData.getItem(storeItemId);
		storeItemModel.setOrder(ProductData.getById(storeItemModel.getProductId()).getTotalOrderQuantity());
		
		TransactionData transactionData = new TransactionData();
		List<TransactionModel> list = transactionData.getList(storeItemId);
		
		request.setAttribute("storeItemModel", storeItemModel);
		request.setAttribute("list", list);

		try {
			request.getRequestDispatcher("/admin/pages/list_transaction.jsp").forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		}
	}
}